// SCENARIO SCRIPT

// This is the special script for your entire scenario. It contains
// special encounters and code accessable from anywhere in the scenario. it also
// contains the code that initializes important special things in the
// scenario (like shops and names and descriptions of special items).

// You can create your own states, but you should give all of them numbers greater than
// or equal to 10.

beginscenarioscript;

variables;
short mynum,bmessage;

body;

// This is the state that is called every time the scenario is loaded,
// even when a save file in the scenario is loaded. Some things that should go here:
//    Names and descriptions of special items.
//    Names and effects of custom special abilities.
beginstate LOAD_SCEN_STATE;

	init_special_item(1,"Malachai's Key","This key belongs to Dervish Malachai, who is now well and deceased.  It opens his quarters.");
	init_special_item(2,"Casimir's Journal","This is the journal of Casimir, also known as Zenbu, the tortured nephil who was once human.");

break;

// This is the state that is called only once at the very beginning of 
// the scenario. Some things that should go here:
//    The stuff in shops.
//    Creating horses and boats.
beginstate START_SCEN_STATE;
	// Initialize a few shops.
	
	// Shop 0 - armor
	add_item_to_shop(0,25,25);
	add_item_to_shop(0,26,20);
	add_item_to_shop(0,30,20);
	add_item_to_shop(0,31,10);
	add_item_to_shop(0,35,10);
	add_item_to_shop(0,121,15);
	add_item_to_shop(0,122,15);
	add_item_to_shop(0,126,3);
	add_item_to_shop(0,131,2);
	add_item_to_shop(0,111,15);
	add_item_to_shop(0,16,10);
	add_item_to_shop(0,136,10);
	add_item_to_shop(0,137,10);
	add_item_to_shop(0,141,5);
	
	// Shop 1 - weapons
	add_item_to_shop(1,45,25);
	add_item_to_shop(1,46,20);
	add_item_to_shop(1,50,15);
	add_item_to_shop(1,51,10);
	add_item_to_shop(1,55,5);
	add_item_to_shop(1,65,20);
	add_item_to_shop(1,66,10);
	add_item_to_shop(1,70,5);
	
	// Shop 2 - tools
	add_item_to_shop(2,170,500);
	add_item_to_shop(2,171,500);
	add_item_to_shop(2,172,30);
	add_item_to_shop(2,174,500);
	add_item_to_shop(2,177,500);
	
	// Shop 3 - missiles
	add_item_to_shop(3,85,500);
	add_item_to_shop(3,86,10);
	add_item_to_shop(3,90,10);
	add_item_to_shop(3,95,3);
	add_item_to_shop(3,100,20);
	add_item_to_shop(3,101,10);
	add_item_to_shop(3,105,10);

	// Shop 4 - potions
	add_item_to_shop(4,220,4);
	add_item_to_shop(4,221,3);
	add_item_to_shop(4,222,3);
	add_item_to_shop(4,223,2);

	// Shop 5 - food
	add_item_to_shop(5,4,500);
	add_item_to_shop(5,6,500);
	add_item_to_shop(5,7,500);

	mynum = get_ran(1,1,2);
	set_flag(99,0,mynum);

	set_ticks_forward(4400);
	set_flag(99,8,1);

break;

// This state is called every tick wherever the party is in the scenario.
// You can use the set_state
beginstate START_STATE;

	if(char_ok(0) == FALSE && get_flag(2,0) >= 10){
		message_dialog("You are dead.  The rest of your small unit will have to live without you.  Your adventure has ended.","");
		end_scenario(0);
	}

	if(get_flag(99,8) == 1){
		if(is_outdoor() == 1){
			set_ticks_forward(-10);
			change_char_energy(1000,1);
		}
		if(is_outdoor() == 0){
			set_ticks_forward(-1);
		}
	}

break;

// Place your own states below. Give each a number at least 10.

beginstate 10;

	if(is_combat() == 1){
		print_str_color("Not in combat!",1);
		end();
	}

	if(get_highest_skill(42) >= 12){
		if(has_recipe(7) == 0){
			message_dialog("The moldy tome here with the title of _Quaff of Rejuvenation_ describes the process of making the most concentrated forms of healing herbs, combining with it the essence of toadstool to prevent the extreme potency from becoming toxic.","You are able to digest the contents, allowing you to make Healing Elixirs.");
			give_recipe(7);
		}
		else{
			message_dialog("The moldy tome here with the title of _Quaff of Rejuvenation_ describes the process of making the most concentrated forms of healing herbs, combining with it the essence of toadstool to prevent the extreme potency from becoming toxic.","You already know how to make Healing Elixirs.");
		}
	}
	else{
		message_dialog("This dusty tome is very complex.  Despite the breadth of your knowledge, you are not able to comprehend this book's contents.","");
	}

break;

beginstate 11;

	if(is_combat() == 1){
		print_str_color("Not in combat!",1);
		end();
	}

	if(get_highest_skill(42) >= 12){
		if(has_recipe(8) == 0){
			message_dialog("The moldy tome here with the title of _Swift Swallow_ describes taking the stimulants in energetic herbs, using toadstools to prevent toxicity and spiritual herbs to prevent mindlessness.","You are able to digest the contents, allowing you to make Hasting Elixirs.");
			give_recipe(8);
		}
		else{
			message_dialog("The moldy tome here with the title of _Swift Swallow_ describes taking the stimulants in energetic herbs, using toadstools to prevent toxicity and spiritual herbs to prevent mindlessness.","You already know how to make Hasting Elixirs.");
		}
	}
	else{
		message_dialog("This dusty tome is very complex.  Despite the breadth of your knowledge, you are not able to comprehend this book's contents.","");
	}

break;

beginstate 12;

	if(is_combat() == 1){
		print_str_color("Not in combat!",1);
		end();
	}

	if(get_highest_skill(42) >= 12){
		if(has_recipe(9) == 0){
			message_dialog("The moldy tome here with the title of _Enchanted Elixirs_ describes the process of taking the mental potency of spiritual herbs and combining it with the soothing effects of graymold to prevent lightheadedness.","You are able to digest the contents, allowing you to make Healing Elixirs.");
			give_recipe(9);
		}
		else{
			message_dialog("The moldy tome here with the title of _Quaff of Rejuvenation_ describes the process of making the most concentrated forms of healing herbs, combining with it the essence of toadstool to prevent the extreme potency from becoming toxic.","You already know how to make Healing Elixirs.");
		}
	}
	else{
		message_dialog("This dusty tome is very complex.  Despite the breadth of your knowledge, you are not able to comprehend this book's contents.","");
	}

break;

beginstate 13;

	reset_dialog();
	add_dialog_str(0,"The Legacy of Ivalice",40);
	add_dialog_str(1,"A story of bravery, written by Private Rufus",20);
	add_dialog_choice(0,"Read it.");
	add_dialog_choice(1,"Don't read it.");
	bmessage = run_dialog(1);
	if(bmessage == 2)
		end();

	reset_dialog();
	add_dialog_str(0,"The Province Ivalice in Valorim / Was home to crazed, invading Nephilim. / Twelve men had survived their first attack, / And those twelve tried to hold the kitties back.",0);
	add_dialog_str(1,"Alas, said things would not come whence the haze, / We soldiers have been holed up for some days. / The nephs have armed their fort, which now displays / Their numbers and their weapons, which amaze.",0);
	add_dialog_str(2,"And so we stand here murking in our hole, / Whilst in a situation truly droll, / With Dervish Malachai who keeps us whole. / He fights to keep us safe from feline vole.",0);
	add_dialog_str(3,"And so the twelve men here stare at the fire, / The swath of us all moaning out our ire / That we be here until we shall expire / Within the walls of somewhere truly dire.",0);
	add_dialog_choice(0,"Continue");
	add_dialog_choice(1,"Stop");
	bmessage = run_dialog(1);
	if(bmessage == 2)
		end();

	reset_dialog();
	add_dialog_str(0,"Now Janet guards the gate with hair so fine, / Dear Ivy is a gal who's true divine, / This author, Rufus, master of the rhyme, / And Gregor, strong and philistine.",0);
	add_dialog_str(1,"Acacia, whose mind is fraught with rage, / And Isabel, who's silent like a sage, / Don't leave Paolo out; the archer paige, / Nor should you take dear Maxwell's sword off stage.",0);
	add_dialog_str(2,"The Bladesman Anthony wants to leave for home, / as is the case amongst those in this tome, / Except for Lloyd, the blade of perfect form. / These men are those I fight with to keep warm.",0);
	add_dialog_str(3,"The leader of our outfit keeps us spry, / With wit and charm and moxie off the fly. / The Dervish keeps us safe with open eye, / The saintly fellow's name is Malachai.",0);
	add_dialog_choice(0,"Continue");
	add_dialog_choice(1,"Stop");
	bmessage = run_dialog(1);
	if(bmessage == 2)
		end();

	reset_dialog();
	add_dialog_str(0,"",0);
	add_dialog_str(1,"",0);
	add_dialog_str(2,"",0);
	add_dialog_str(3,"",0);
	add_dialog_choice(0,"Continue");
	add_dialog_choice(1,"Stop");
	bmessage = run_dialog(1);
	if(bmessage == 2)
		end();


break;

beginstate 14;

	set_char_status(who_used_custom_item(),0,160,1,0);

break;

